<template>
<!-- 引入资产 -->
	<Modal
        v-model="rzShow"
        title="引入资产"
		:width="1000"
        >
        <div>
			<Form :model="info" :label-width="150" style="width: 100%" :rules="ruleValidate" ref="from">
				<Row>
					<Col span="12">
						<FormItem label="导入时间范围：" prop="date">
							<DatePicker :value="info.date.split('|')" type="daterange" placement="bottom-end" placeholder="请选择日期" style="width: 240px" @on-change="date_change"></DatePicker>
						</FormItem>
					</Col>
				</Row>
				<Row>
					<Col span="12">
						<FormItem label=" 类型：">
							<Select v-model="info.type" placeholder="请选择类型" style="width: 240px">
								<Option :value="-1" >全部</Option>
								<Option :value="0" >现金</Option>
								<Option :value="1" >银行</Option>
								<Option :value="2" >其他</Option>
							</Select>
						</FormItem>
					</Col>
					<Col span="12">
						<FormItem label="承担部门：">
							<bumen_filter v-model="info.bumen" field="name" style="width: 240px"></bumen_filter>
						</FormItem>
					</Col>
				</Row>
				<Row>
					<Col span="12">
						<FormItem label="公司主体：">
							<company_list v-model="info.company" field="name" style="width: 240px"></company_list>
						</FormItem>
					</Col>
					<Col span="12">
						<FormItem label="费用科目：">
							<subject_filter v-model="info.subject" field="name" style="width: 240px"></subject_filter>
						</FormItem>
					</Col>
				</Row>
				<Row>
					<Col span="12">
						<FormItem label="地区：">
							<region_list v-model="info.region" field="name" style="width: 240px"></region_list>
						</FormItem>
					</Col>
				</Row>
				
			</Form>
		</div>
		<div slot="footer" style="text-align: center;">
			<Button type="success" size="large"  @click="handleSubmit('from')">导入</Button>
		</div>
    </Modal>
</template>

<script>
import region_list from '@/themes/components/region_list';
import company_list from '@/themes/components/company_list';
import bumen_filter from '@/themes/components/bumen_filter';
import subject_filter from '@/themes/components/subject_filter';
export default {
  name: 'zichan_bar',
  data(){
	return {
		// title:'引入入账',
		rzShow:false,
		info:{
			date:'',
			type:'',
			region:'',
			company:'',
			bumen:'',
			subject:'',
		},
		ruleValidate:{
			date:[
				{ required: true, message: '导入时间范围不能为空', trigger: 'blur' }
			]
		},
	};
  },
  components:{
		region_list,
		company_list,
		bumen_filter,
		subject_filter,
	},
  props:['value','subject','cinfo'],
  created(){
	this.show = this.value;

	var cur_month = localStorage.account_balance?localStorage.account_balance:'';
	if(cur_month){
		this.info.date = cur_month+'-01|'+cur_month+'-01';
	}
  },
  watch:{
	value(val){
		if(val && this.cinfo){
			this.info.subject = this.cinfo.subject;
		}
		this.rzShow = val;
	},
	rzShow(val){
		this.$emit('input',val);
	},
	
  },
  methods: {
	handleSubmit(name) {
		this.$refs[name].validate((valid) => {
			if (valid) {
				this.einfo_ok();
			} 
		})
	},
	einfo_ok(){
	
		var self = this;
		var postdata = {
			f:this.info
		};
		
		Whttp.load('Accounting/Assets/yinru',postdata,function(result){//console.log(result);return false;
			self.rzShow = false;
			self.$Message.info('提交成功');
			self.$emit('success',result);
		});
		
	},
	date_change(date){
		this.info.date = date.join('|');
	}
  }
}
</script>
<style scoped>
.price{
	color: red;
    margin: 0 5px;
}
.defwid{
	width:220px;
}
</style>